import axios from 'axios'
import { host } from './config'


const getVueCode = (componentName) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'get',
      url: `${host}/vueCode/${componentName}/index.txt`,
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      console.log(err)
    })
  })
}

const importFile = ({folder, file}) => {
  const importObj = import.meta.globEager('@/components_source/**');
  for (const key in importObj) {
    if (key.indexOf(`${folder}/${file}`) != -1) {
      return importObj[key].default
    }
  }
}

export {
  getVueCode,
  importFile,
}
